
from PyQt5 import QtCore

from model import Serial


class SerialThread(QtCore.QThread):
    def __init__(self, ser:Serial, parent=None):
        super().__init__()
        self.ser = ser
        self.parent = parent
        self.msg_is_open = True 

    def run(self):
        self.msg_is_open = True
        while self.msg_is_open:
            self.ser.serial_read()           
            print(self.ser.data)
            if self.ser.data <= 240:
                self.parent.current_player = self.parent.red_player
            if self.ser.data >= 460:
                self.parent.current_player = self.parent.blue_player
                
    def stop(self):
        self.msg_is_open = False
        self.parent.current_player = None